package com.f6.common.util;

import com.f6.common.constants.CommonCanstants;
import com.f6.common.service.CommonService;
import com.f6.menuUtils.AccessToken;

import common.weixinutils.response.TextMessage;

/**
 * 访问数据系统接口工具类
 * 
 * @author
 *
 */
public class DataAccessUtil {

	public static void main(String[] args) {
		
	}

	public static String pushWeiXinMessage(TextMessage textMessage,String appid, String appsecret) {
		System.out.println("进了该方法＝＝＝");
		// 封装请求参数
		StringBuffer params = new StringBuffer();
		
		params.append("{").append("\"touser\"").append(":").append("\"")
				.append(textMessage.getToUserName()).append("\"").append(",");
		params.append("\"msgtype\"").append(":").append("\"")
				.append(MessageUtil.RESP_MESSAGE_TYPE_TEXT).append("\"")
				.append(",");
		params.append("\"text\"").append(":").append("{");
		params.append("\"content\"").append(":").append("\"")
				.append(textMessage.getContent()).append("\"");
		params.append("}");
		params.append("}");

		System.out.println("params===="+params);
		// 获取token
		//启动获取token线程
		//AccessToken at = WeixinUtil.getAccessToken(CommonCanstants.appId, CommonCanstants.appSecret);
		String token = CommonService.getToken(appid, appsecret);
		String url = CommonCanstants.SEND_WEIXIN_MESSAGE_URL
				.replace("ACCESS_TOKEN", token);
		System.out.println("请求路径:" + url);

		try {
			String jsonStr = HttpUtil.getJsonSring(params.toString(), url);
			
			return "0000";
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "0001";

	}
}
